# Create your views here.
#from django.http import HttpResponse
from django.shortcuts import render_to_response
#from django.http import Http404
#from django.template import Context, loader
import sys
from time import time
sys.path.append('./gen-py')
#import search.feeds
from search.feeds import FeedManager
#from feedthing.entry import ZEntry
#e = ZEntry()
import uuid

fm = FeedManager()

def index(request):
    return HttpResponse("word em up!")

def search(request):
    query = request.GET.get('q', '').encode('utf-8')
    type = request.GET.get('type', 'content')
    offset = request.GET.get('offset', 0)
    if offset:
        offset = int(offset)  
    entries = None
    total = None
    next = None
    prev = None
    took = None
    if query:
        t0 = time()
#        (total, entries) = fm.search_entries("content:(%s)" % query, offset)
        (total, entries) = fm.search_entries("%s:(%s)" % (type, query), offset)
        took = "%.2f" % (time() - t0)
#        next = (total > len(tweets) + offset) and (offset + len(tweets)) or None
 #       prev = (offset > 0) and (offset - 10) or None

    return render_to_response("search/tmpl.html", {
        "entries": entries,
        "query": query,
        "took" : took,
        "total" : total,
#        "current": offset,
#        "next": next,
#        "prev": prev
       })      


